//
//  SWAddressCreateReq.swift
//  ChildStory
//
//  Created by linhan on 2017/1/18.
//  Copyright © 2017年 Aiya. All rights reserved.
//

import Foundation

class SWAddressCreateReq: SWBaseRequest
{
    var info:SWAddresseeInfo
    
    init(info:SWAddresseeInfo)
    {
        self.info = info
        super.init()
        api = SWRequestAPI.AddressCreate
    }
    
    override var url:String
    {
        return "http://mpic.bbyiya.com/user/addOrEditAddr"
    }
    
    override var params:Any?
    {
        var data:[String:Any] = [:]
        data["reciver"] = info.receiver
        data["phone"] = info.phone
        data["province"] = info.provinceCode
        data["city"] = info.cityCode
        data["area"] = info.districtCode
        data["streetdetail"] = info.block
        data["postcode"] = info.postcode
        if info.addressID > 0
        {
            data["addrid"] = info.addressID
        }
        
        let jsonString:String = JSONHelper.JSONEncode(data)
        trace("SWAddressCreateReq", jsonString)
        
        return ["addrJson":jsonString]
    }
    
    override func JSONToModel(_ json:JSON, JSONString:String, JSONData:Data) -> AnyObject?
    {
        trace(json)
        return Mapper<SWAddressCreateRsp>().map(JSONString: JSONString)
    }
}

class SWAddressCreateRsp: NSObject,Mappable
{
    var statu:String?
    var info:SWAddresseeInfoRsp?
    
    
    required init?(map: Map) { }
    
    // Mappable
    func mapping(map: Map) {
        statu                   <- map["Statu"]
        info                    <- map["BaseModle"]
    }
}

